﻿namespace Sai.Core.Reporting
{
	using System;

	public class ReportFormatterFactory : IReportFormatterFactory
	{
		public ReportFormatterFactory(ProductReleaseProject project)
		{
			this.Format = project.ReportFormat;
			this.HeadContent = project.ReportStyler.HeadTag;
			this.StyleContent = project.ReportStyler.StyleTag;
			this.HeaderText = project.ReportStyler.HeadingText;
			this.FooterText = project.ReportStyler.FooterText;
		}

		private ReportFormat Format { get; set; }

		private string HeadContent { get; set; }

		private string StyleContent { get; set; }

		private string HeaderText { get; set; }
	
		private string FooterText { get; set; }

		public IReportFormatter Create()
		{
			IReportFormatter formatter = null;

			switch (this.Format)
			{
				case ReportFormat.Xml:

					formatter = new XmlReportFormatter();
					break;

				case ReportFormat.Html:
                case ReportFormat.Html4:

					formatter = new HtmlReportFormatter()
					{
						HeadContent = this.HeadContent,
						StyleContent = this.StyleContent,
						HeaderText = this.HeaderText,
						FooterText = this.FooterText
					};
					break;

				case ReportFormat.Maml:

					formatter = new MamlReportFormatter();
					break;

                case ReportFormat.Md:

                    formatter = new MarkdownReportFormatter();
                    break;

				default:

					throw new ArgumentException("Unrecognised report format", "format");
			}

			return formatter;
		}
	}
}
